﻿using SolidPrinciples.DependencyInversion.BusinessLayer;

namespace SolidPrinciples.DependencyInversion.UserInterfaceLayer
{
    internal class PointOfSaleTerminalPresenter
    {
        private readonly PointOfSaleTerminal _pointOfSaleTerminal;
        private readonly PointOfSaleTerminalView _view;

        public PointOfSaleTerminalPresenter(PointOfSaleTerminalView view)
        {
            _pointOfSaleTerminal = new PointOfSaleTerminal();
            view.NewProductRegisterPressed += ViewOnNewProductRegisterPressed;
            _view = view;
        }

        private void ViewOnNewProductRegisterPressed(object sender, NewProductRegisterPressEventArgs args)
        {
            _pointOfSaleTerminal.Register(productSku: args.ProductSku, amount: args.Amount);
            _view.Show(_pointOfSaleTerminal.Products);
            _view.ShowSumToPay(_pointOfSaleTerminal.SumToPay);
        }
    }
}